<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('下派办理期限配置')"/>
    <link th:href="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.css}" rel="stylesheet">
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-config-add" name="form-config-add" th:object="${deferAuto}">
        <input name="deptId" th:value="${deferAuto != null ? deferAuto.deptId : dept.noUnit}" type="hidden">
        <input name="deptName" th:value="${deferAuto != null ? deferAuto.deptName : dept.deptName}" type="hidden">
        <div class="col-sm-12">
            <div class="form-group">
                <label class="col-xs-3 control-label-new" style="padding-top: 0;">是否开启：</label>
                <div class="col-xs-9">
                    <input name="isOpen" th:checked="${deferAuto?.isOpen == 1}" th:value="${deferAuto != null ? deferAuto.isOpen : 0}"
                           type="checkbox" data-size="small">
                </div>
            </div>
        </div>
        <div class="col-sm-12">
            <div class="form-group">
                <label class="col-xs-3 control-label-new">延期次数：</label>
                <div class="col-xs-9">
                    <input type="text" class="form-control" name="deferTimes" th:value="${deferAuto != null ? deferAuto.deferTimes : 2}">
                </div>
            </div>
        </div>
        <div class="col-sm-12">
            <div class="form-group">
                <label class="col-xs-3 control-label-new">延期天数：</label>
                <div class="col-xs-9">
                    <input type="text" class="form-control" name="deferDays" th:value="${deferAuto != null ? deferAuto.deferDays : 5}">
                </div>
            </div>
        </div>
        <div class="col-sm-12" hidden="hidden">
            <div class="form-group">
                <label class="col-xs-3 control-label-new">延期条件：</label>
                <div class="col-xs-9">
                    <input type="text" class="form-control" name="deferCondition" disabled="disabled" th:value="${deferAuto != null ? deferAuto.deferCondition : 0}">(临期天数)
                </div>
            </div>
        </div>
        <div class="row" style="margin-top:50px;">
            <div class="col-xs-offset-5 col-xs-10">
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/ajax/libs/bootstrap-switch/bootstrap-switch.min.js}"></script>
<script type="text/javascript">
    var prefix = ctx + "system/deferAuto";

    $("#form-config-add").validate({
        rules: {
            onkeyup: false,
            deferTimes: {
                digits: true,
                range:[1,3]
            },
            deferDays: {
                digits: true,
                range:[1,5]
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $('#form-config-add').serializeArray();
            $.operate.save(prefix + "/saveOrUpdate", data);
        }
    }

    $('[name="isOpen"]').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
        size: "mini",
        onSwitchChange: function (event, state) {
            if (state === true) {
                $(this).val(1);
            } else {
                $(this).val(0);
            }
        }
    });

</script>
</body>
</html>
